package com.fyw.magichome.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.fyw.magichome.R;
import com.fyw.magichome.bean.CameraList;

import java.util.List;

/**
 * Created by FYW on 2017/9/26.
 */

public class CameraListAdapter extends BaseAdapter {
    private Context context;
    private List<CameraList.DataBean> list;

    public CameraListAdapter(Context context, List<CameraList.DataBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.item_camera_list, null);
            viewHolder = new ViewHolder();
            viewHolder.cameraImg = (ImageView) view.findViewById(R.id.cameraImg);
            viewHolder.cameraName = (TextView) view.findViewById(R.id.cameraName);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        viewHolder.cameraName.setText(list.get(i).getChannelName());

        Glide.with(context)
                .load(list.get(i).getPicUrl())
                .into(viewHolder.cameraImg);

        return view;
    }

    class ViewHolder {
        TextView cameraName;
        ImageView cameraImg;
    }
}
